<%@page import="helpers.UrlHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.Link"%>
<%@page import="java.util.List"%>
<%@page import="java.util.TreeMap"%>
<%@page import="systems.ConfigSystem"%>
<%@page import="entities.SiteConfig"%>
<%
SiteConfig siteConfig = ConfigSystem.getConfigs();
TreeMap<String, String> check = (TreeMap<String, String>) request.getAttribute("check");
List<Category> categories = (List<Category>) request.getAttribute("categories");
Link link = (Link) request.getAttribute("link");

String success = (String) request.getAttribute("success");
String form = (String) request.getAttribute("form");
%>


<jsp:include page="/templates/classic/layouts/header.jsp" />

		<h2 class="title">Submit Link</h2>
		<div class="dir">
			<a href="/submit-site">Submit Link</a> <> 
		</div>
		<br />
		<div class="submit-form">
			<form method="post">
			<%=success == null? "" : success %>
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Add Link</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="title">Name</td>
						<td>
							<% if (check.get("name") != null) { %>
								<div class="error"><%=check.get("name")%></div>
							<% } %>
							<input type="text" name="name" value="<%=link.getName()%>">
						</td>
					</tr>
					<tr>
						<td class="title">Description</td>
						<td>
							<% if (check.get("description") != null) { %>
								<div class="error"><%=check.get("description")%></div>
							<% } %>
							<textarea name="description" rows="5" cols="50"><%=link.getDescription() == null ? "" : link.getDescription() %></textarea>
						</td>
					</tr>
					<tr>
						<td class="title">Url</td>
						<td>
							<% if (check.get("url") != null) { %>
								<div class="error"><%=check.get("url")%></div>
							<% } %>
							<input type="text" name="url" value="<%=link.getUrl() == null ? "" : link.getUrl() %>">
							<a href="#" class="get-info">Get info</a>
						</td>
					</tr>
					<tr>
						<td class="title">Category</td>
						<td>
							<% if (check.get("category") != null) { %>
								<div class="error"><%=check.get("category")%></div>
							<% } %>
							<select name="category">
								<%
								for (int i = 0; i < categories.size(); i++) {
								%>
								<option value="<%=categories.get(i).getId()%>" <%=categories.get(i).getId() == link.getCategory()? "selected=\"selected\"" : "" %>>
									|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
									<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
								</option>
								<%
								}
								%>
							</select>
						</td>
					</tr>
					<tr class="type">
						<td class="title">Type</td>
						<td>
							<% if (check.get("type") != null) { %>
								<div class="error"><%=check.get("type")%></div>
							<% } %>
							<input type="radio" name="type" value="free" <%=link.getType().equals("free") ? "checked=\"checked\"" : "" %> <%=form.equalsIgnoreCase("edit") ? "disabled=\"disabled\"" : "" %>> Free
						</td>
					</tr>
					<tr class="dotline">
						<td class="title">Captcha</td>
						<td>
							<% if (check.get("captcha") != null) { %>
								<div class="error"><%=check.get("captcha")%></div>
							<% } %>
							<script>
					        	var RecaptchaOptions = { theme : 'clean' };
					  		</script>
							<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<button type="submit">Save</button>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
<script type="text/javascript" src="/templates/<%=siteConfig.getTemplate() %>/js/link-form.js"></script>
<script type="text/javascript">
<!--
 var server = "<%=UrlHelper.getServerUrl(request)%>";
//-->
</script>
<jsp:include page="/templates/classic/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>